package com.zzj.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println("自动填充");
        this.strictInsertFill(metaObject, "createTime",  String.class,format.format(new Date())); // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "updateTime",  String.class,format.format(new Date())); // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "registerTime",  String.class,format.format(new Date())); // 起始版本 3.3.3(推荐)
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        System.out.println("自动填充");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.strictUpdateFill(metaObject, "updateTime",  String.class,format.format(new Date())); // 起始版本 3.3.3(推荐)
    }



}
